package fnord.jovian.tango;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.*;

import fnord.jovian.TheBoard;

public abstract class TheMenu extends ThePanel {

	protected RectangularShape _mask;
	protected TheBoard _board;

	public TheMenu() {
		super();
	}

	public TheMenu(double w, double h, TheBoard board) {
		super((double)(board.getWidth()-w)/2.0,(double)(board.getHeight()-h)/2.0,w,h, board);
		_board = board;
		_mask = new Rectangle2D.Double(0,0,board.getWidth(),board.getHeight());
	}

	public void paint(Graphics2D g) {
		double height = _layout.getPadding()*2;
		for (int i = 0; i < _objects.size(); i++) {
			height += _objects.get(i).getHeight() + 10;
		}
		setSize(_shape.getWidth(), height);
		resize();
		if (_mask != null) {
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
			g.setColor(Color.BLACK);
			g.fill(_mask);
			g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
		}
		super.paint(g);
	}

	public void resize() {
		_shape.setFrame((double)(_board.getWidth()-_shape.getWidth())/2.0,(double)(_board.getHeight()-_shape.getHeight())/2.0,_shape.getWidth(),_shape.getHeight());
		if (_mask != null)
			_mask.setFrame(_mask.getX(), _mask.getY(), _board.getWidth(), _board.getHeight());
	}

}